/*
 * @Author: 晟松
 * @Date: 2021-12-07 20:03:23
 * @LastEditors: 晟松
 * @LastEditTime: 2022-02-04 16:54:24
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\model\Student.js
 * @Description:
 */
import Sequelize from "sequelize";
import { isValidateEnum } from "@main/util/ValidateUtil";
import { ParamError } from "../common/CommonError";
import enums from "@main/config/enums";

export const modelName = "student";

const DataTypes = Sequelize.DataTypes;

export const attributes = {
    identity: {
        type: DataTypes.INTEGER,
        validate: {
            check(val) {
                if (val != enums["identity"]["student"]) {
                    throw new ParamError(`identity student: ${val}值错误`);
                }
            },
        },
    },
    userName: {
        type: DataTypes.STRING,
    },
    avatar: {
        type: DataTypes.STRING,
    },
    gender: {
        type: DataTypes.INTEGER,
        validate: {
            check(val) {
                if (!isValidateEnum(val, "gender")) {
                    throw new ParamError(`gender: ${val}值错误`);
                }
            },
        },
    },
    schoolName: {
        type: DataTypes.STRING,
    },
    // 只指定类型时的缩写
    college: DataTypes.STRING,
    grade: {
        type: DataTypes.INTEGER,
        validate: {
            check(val) {
                if (!isValidateEnum(val, "grade")) {
                    throw new ParamError(`grade: ${val}值错误`);
                }
            },
        },
    },
    major: DataTypes.STRING,
    studentId: DataTypes.STRING, // 学号
    introduction: DataTypes.STRING,
    available: DataTypes.BOOLEAN, // 是否被辅导员审核通过，即是否可用
    timeIntegral: DataTypes.INTEGER, // 时间积分数
    // 这两个是关于区块链的一个记录，主要是记录其中的交易hash和块hash，通过这两个hash就可从区块链中获取到对应的信息
    transactionHash: DataTypes.STRING,
    blockHash: DataTypes.STRING,
};

export const options = {
    // tableName: "t_user_reference",
};
